﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LANmine
{
    public partial class HomeForm : Form
    {
        private Language lmLang;

        public HomeForm(Language lmLang)
        {
            /** Save the language object */
            this.lmLang = lmLang;

            /** Dock the window */
            this.Dock = DockStyle.Fill;

            InitializeComponent();
            ApplyLanguage();

            /** Load some stats */
            setAmountOfUsers();
            setAmountOfTeams();
            setAmountOfOrders();
            setAmountOfComps();
        }

        #region member functions

        private void setAmountOfUsers()
        {
            DataTable dt = new DataTable("deelnemers");
            SqlDataAdapter da;
            Database myDb = new Database("ro");

            try
            {
                // SqlDataAdapter
                da = new SqlDataAdapter("select COUNT(id) as aantalusers from deelnemers", myDb.getDbConn());
                da.Fill(dt);
                lblUsers.Text += " " + dt.Rows[0]["aantalusers"].ToString();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }

        private void setAmountOfTeams()
        {
            DataTable dt = new DataTable("teams");
            SqlDataAdapter da;
            Database myDb = new Database("ro");

            try
            {
                // SqlDataAdapter
                da = new SqlDataAdapter("select COUNT(id) as aantalteams from compos_teams", myDb.getDbConn());
                da.Fill(dt);
                lblTeams.Text += " " + dt.Rows[0]["aantalteams"].ToString();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }

        private void setAmountOfOrders()
        {
            DataTable dt = new DataTable("orders");
            SqlDataAdapter da;
            Database myDb = new Database("ro");

            try
            {
                // SqlDataAdapter
                da = new SqlDataAdapter("select COUNT(id) as aantalorders from catering_bestellingen", myDb.getDbConn());
                da.Fill(dt);
                lblOrdersIP.Text += " " + dt.Rows[0]["aantalorders"].ToString();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }

        private void setAmountOfComps()
        {
            DataTable dt = new DataTable("compos");
            SqlDataAdapter da;
            Database myDb = new Database("ro");

            try
            {
                // SqlDataAdapter
                da = new SqlDataAdapter("select COUNT(id) as aantalcompos from games", myDb.getDbConn());
                da.Fill(dt);
                lblComps.Text += " " + dt.Rows[0]["aantalcompos"].ToString();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }

        #endregion


        #region Language Specifications
        /**
         * MainForm::ApplyLanguage()
         * ---------------------------
         * Overwrite the text property of all elements in this form with the right ones.
         */
        private void ApplyLanguage()
        {
            /**
             * Header label
             */
            this.lblWelcome.Text = this.lmLang.GetString("home.lblWelcome"); // Label is the same as the nav button
            /**
             * Label welkomsttekst
             */
            this.lblWelcomeText.Text = this.lmLang.GetString("home.lblWelcomeText");
            this.lblUsers.Text = this.lmLang.GetString("home.lblUsers");
            this.lblTeams.Text = this.lmLang.GetString("home.lblTeams");
            this.lblComps.Text = this.lmLang.GetString("home.lblComps");
            this.lblOrdersIP.Text = this.lmLang.GetString("home.lblOrdersIP");

        }
        #endregion
    }
}
